#ifndef SCRIPTFILE_H
#define SCRIPTFILE_H

#include <QString>
#include <QList>

#include "command.h"

namespace SDHuaYi_Script
{
    // 定义关键字
    enum enum_KEYWORD
    {
        KEYWORD_define = 0,
        KEYWORD_integer,
        KEYWORD_string,
        KEYWORD_if,
        KEYWORD_call,
        KEYWORD_goto,
        KEYWORD_ret,
        KEYWORD_pause,
        KEYWORD_exit,
        KEYWORD_f_flagerr,
        KEYWORD_insert,
        KEYWORD_other
    };

    class ScriptLabel
    {
    public:
        qint32 LineNum;
        QString Name;

        ScriptLabel();
        ScriptLabel(qint32 lineNum, QString name) : LineNum(lineNum), Name(name) {}
    };

    /* 脚本文件 */
    class ScriptFile
    {
    public:
        QList<command> ScriptCmds = QList<command>();
        QList<ScriptLabel> Labels = QList<ScriptLabel>();
        qint32 cmdStartIndex = 0;

    public:
        ScriptFile();
        ScriptFile(QList<command> cmds, QList<ScriptLabel> labels) : ScriptCmds(cmds), Labels(labels) {}

        /* 将字符串解析为指令 */
        command getCommand(QString scmd, qint32 lineNum = 0, qint32 startIndex = 0);

        /* 展开include的文件 */
        void spreadInclude(QString scmd);

        /* 脚本展开 */
        void ScriptSpread(QString script, QString path);
        void ScriptSpread(QString ScriptFileName);

    private:
        QString Name = NULL; // 存放当前脚本路径

        /* 将include 相对路径处理为绝对路径 */
        QString GetFileName(QString currentDir, QString cileName);

        /* 获取关键字对应的编号 */
        enum_KEYWORD getKeyWord(QString keyWord);
    };
}
#endif // SCRIPTFILE_H
